package com.xingdata.jjxc.views;

import java.util.ArrayList;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.graphics.Typeface;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;

import com.xingdata.jjxc.R;
import com.xingdata.jjxc.callback.DilalogListener;
import com.xingdata.jjxc.utils.JUtils;

/** 自定义Dialog的一个类 */
public class MyAlertDialog {
	private Context mContext;
	private DilalogListener mDilalogListener;
	private ArrayList<String> mTitles;

	public MyAlertDialog(Context context, ArrayList<String> titles, DilalogListener listener) {
		this.mContext = context;
		this.mDilalogListener = listener;
		this.mTitles = titles;
		showDialog();
	}

	private void showDialog() {
		// 设置字体
		Typeface font = Typeface.createFromAsset(mContext.getAssets(), JUtils.TypefacePath);
		final Dialog exitDialog = new Dialog(mContext, R.style.my_dialog);
		View v = LayoutInflater.from(mContext).inflate(R.layout.pop_register, null);
		LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
		exitDialog.addContentView(v, params);
		View blank = v.findViewById(R.id.register_view);

		TextView exit_textView = (TextView) v.findViewById(R.id.exit_TextView);
		exit_textView.setText(mTitles.get(0));
		exit_textView.setTypeface(font);

		Button exit = (Button) v.findViewById(R.id.register_exit);
		exit.setText(mTitles.get(1));
		exit.setTypeface(font);
		
		Button cancel = (Button) v.findViewById(R.id.register_no);
		cancel.setText(mTitles.get(2));
		cancel.setTypeface(font);
		
		exit.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View arg0) {
				mDilalogListener.onSure();
				exitDialog.dismiss();
			}
		});

		cancel.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				mDilalogListener.onCancel();
				exitDialog.dismiss();
			}
		});

		blank.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				exitDialog.dismiss();
			}
		});
		exitDialog.show();
	}

}
